// pages/SelfCenter/MyPub/MyPub.js
const app = getApp();
const db = wx.cloud.database();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: '',
    dayList: [],
    bbslist: []
  },
  
  fresh() {
    var that = this;
    
    db.collection('bbs').where({
      pubstuid: app.eduOS.xh
    }).get({
      success(res) {
        that.setData({
          bbslist: res.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    this.setData({
      img: app.globalData.imgList.dayimg
    })
    
    db.collection('bbs').where({
      pubstuid: app.eduOS.xh
    }).get({
      success(res) {
        console.log(res)
        that.setData({
          bbslist: res.data
        })
      }
    })
  },
  delbbs(e) {
    var that = this;
    //console.log(e)
    var info = e.currentTarget.dataset.target;
    console.log(info._id);
    wx.showLoading({
      title: '删除ing~',
    })
    //console.log(info._id);
    wx.cloud.callFunction({
      name: 'removerank',
      data: {
        tablename: 'remarks',
    
        belongs: info._id
      },
      success(res) {
        console.log(res)
        wx.cloud.deleteFile({
          fileList: info.cloudlist
        })
        wx.cloud.callFunction({
          name: 'kindb',
          data: {
            tablename: 'bbs',
            opr: 'del',
            id: info._id
          },
          success(tans) {
            console.log(tans)
            wx.hideLoading();
            that.fresh();
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})